package liumengbaio.lolzhangyoubao.Activity.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import java.util.List;

import liumengbaio.lolzhangyoubao.Activity.InFo.NextFreeHeroInfo;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/8/25.
 */
public class NextFreeHeroAdapter extends BaseAdapter {
    private List<NextFreeHeroInfo> nextfreeHeroInfo;
    private Context context;

    public NextFreeHeroAdapter(List<NextFreeHeroInfo> nextfreeHeroInfo, Context context) {
        this.nextfreeHeroInfo = nextfreeHeroInfo;
        this.context = context;
    }


    @Override
    public int getCount() {
        return nextfreeHeroInfo.size();
    }

    @Override
    public Object getItem(int position) {
        return nextfreeHeroInfo.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_weekfree, null);
            holder.iconhero = (ImageView) convertView.findViewById(R.id.iconhero);
            holder.nickname = (TextView) convertView.findViewById(R.id.nickname);
            holder.money = (TextView) convertView.findViewById(R.id.money);
            holder.point = (TextView) convertView.findViewById(R.id.point);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        NextFreeHeroInfo info = nextfreeHeroInfo.get(position);

        holder.nickname.setText(info.getNickname());
        holder.money.setText(info.getMoney());
        holder.point.setText(info.getPoint());
        Picasso.with(context).load(info.getPic_url()).into(holder.iconhero);
        return convertView;
    }

    private class ViewHolder {
        private TextView nickname, money, point;
        private ImageView iconhero;
    }
}
